/**  
 * All rights Reserved, Designed By <a href="www.itttq.com" target="_blank">www.itttq.com</a>
 * @date:   2018年1月20日 下午12:06:13
 * @Copyright: 2018 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */  
package com.itttq.gshop.pc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.itttq.gshop.domain.po.SysAdPo;
import com.itttq.gshop.domain.po.SysNoticePo;
import com.itttq.gshop.domain.po.WareInfoPo;
import com.itttq.gshop.domain.to.FloorPcTo;
import com.itttq.gshop.generic.connector.ISysAdConnector;
import com.itttq.gshop.generic.connector.ISysFloorPcConnector;
import com.itttq.gshop.generic.connector.ISysNoticeConnector;
import com.itttq.gshop.generic.connector.IWareInfoConnector;
import com.itttq.gshop.generic.util.Constants;
import com.itttq.gshop.generic.util.Constants.AdCategory;
import com.itttq.gshop.generic.util.Constants.WareStatus;

/**   
 * @ClassName:  IndexController
 * @author: 迷蝶
 * @date:   2018年1月20日 下午12:06:13 
 *     
 * @Copyright: 2018 <a href="www.itttq.com" target="_blank">www.itttq.com</a> Inc. All rights reserved. 
 */
@RestController
public class IndexController extends GenericPcController {
	private static final long serialVersionUID = -6485190841311449L;
	@Autowired
	private ISysAdConnector adConnector;
	@Autowired
	private IWareInfoConnector wareConnector;
	@Autowired
	private ISysFloorPcConnector floorPcConnector;
	@Autowired
	private ISysNoticeConnector noticeConnector;
	
	/**
	 * 主页
	 * @return
	 */
	@RequestMapping(value={"index.html", ""})
	public ModelAndView index(HttpServletRequest request) {
		ModelAndView mv = new ModelAndView("/index");
		
		WareInfoPo ware = new WareInfoPo();
		ware.setSales(WareStatus.ONSHELF.getVal());
		ware.setSize(5);
		ware.setSortField("time");
		// 获取活楼层数据前端根据楼层数据展示，TODO GXG 缓存
		List<FloorPcTo> floors = floorPcConnector.getFloorsAndDatas();
		mv.addObject("floors", floors);
		// 获取幻灯
		SysAdPo ad = new SysAdPo();
		ad.setCategory(AdCategory.SLIDE.getVal());
		ad.setStatus(Constants.STATUTS_OPEN);
		mv.addObject("slides", adConnector.getSysAds(ad).getData());
		ad.setCategory(AdCategory.SLIDE_UNDER.getVal());
		ad.setSize(2);
		mv.addObject("recommends", adConnector.getSysAds(ad).getData());
		SysNoticePo notice = new SysNoticePo();
		notice.setStatus(Constants.STATUTS_OPEN);
		notice.setSize(5);
		mv.addObject("notices", noticeConnector.getSysNotices(notice).getData());
		
		mv.addObject("cats", getCats());
		getCommon(request, mv);
		return mv;
	}
	
	/**
	 * 注册页面
	 * @return
	 */
	@RequestMapping("reg.html")
	public ModelAndView register() {
		return new ModelAndView("/reg");
	}

	/**
	 * 登录页面
	 * @return
	 */
	@RequestMapping("login.html")
	public ModelAndView login() {
		return new ModelAndView("/login");
	}
	
	/**
	 * 找回密码页面
	 * @return
	 */
	@RequestMapping("forgetPwd.html")
	public ModelAndView forgetPwd() {
		return new ModelAndView("/forget");
	}
}
